package com.ozo.cloud.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ozo.cloud.manage.entity.SysRolePermissionRel;
import com.ozo.cloud.manage.mapper.SysRolePermissionRelMapper;
import com.ozo.cloud.manage.service.ISysRolePermissionRelService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色权限关系 服务实现类
 * </p>
 *
 * @author qiangesoft
 * @since 2024-07-11
 */
@RequiredArgsConstructor
@Service
public class SysRolePermissionRelServiceImpl extends ServiceImpl<SysRolePermissionRelMapper, SysRolePermissionRel> implements ISysRolePermissionRelService {

    @Override
    public List<Long> getPermissionIdListByRoleId(Long roleId) {
        return this.getPermissionIdListByRoleIdList(Collections.singletonList(roleId));
    }

    @Override
    public List<Long> getPermissionIdListByRoleIdList(List<Long> roleIdList) {
        LambdaQueryWrapper<SysRolePermissionRel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(SysRolePermissionRel::getRoleId, roleIdList);
        return baseMapper.selectList(queryWrapper).stream().map(SysRolePermissionRel::getPermissionId).collect(Collectors.toList());
    }

}
